xquery version "3.0";

module namespace secure="secure";

declare namespace api = "api";

import module namespace config="http://exist-db.org/xquery/apps/config" at "config.xqm";

declare
    %api:login
function secure:login($data){
    xmldb:login($config:app-root, $data/user/string(), $data/password/string(), true()),
    response:redirect-to(xs:anyURI(request:get-header("Referer")))
};

declare
    %api:logout
function secure:logout($data){
    session:invalidate(),
    response:redirect-to(xs:anyURI(request:get-header("Referer")))
};